package cn.anson.jujuapp.utils;

import android.content.Context;
import android.content.SharedPreferences;

import cn.anson.jujuapp.conf.MyConstaints;

/**
 * Created by Anson-pc on 2016/3/20.
 * 操作SP文件的工具类
 */
public class SPUtils {

    /**
     *
     * @param 上下文
     * @param 键
     * @param 值
     */
    public static void putString(Context context, String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(MyConstaints.SPFILENAME, Context.MODE_PRIVATE);
        sp.edit().putString(key, value).commit();
    }

    public static String getString(Context context,String key,String defvalue){
        SharedPreferences sp = context.getSharedPreferences(MyConstaints.SPFILENAME, Context.MODE_PRIVATE);
        return sp.getString(key,defvalue);
    }


    /**
     * 保存activity的创建次数
     * @param context
     * @param key
     * @param value
     */
    public static void  putInt(Context context,String key,int value){
        SharedPreferences sp = context.getSharedPreferences(MyConstaints.SPFILENAME, Context.MODE_PRIVATE);
         sp.edit().putInt(key,value).commit();
    }

    /**
     * 获取activity的创建次数
     * @param context
     * @param key
     * @param value
     * @return
     */
    public static int  getInt(Context context,String key,int value){
        SharedPreferences sp = context.getSharedPreferences(MyConstaints.SPFILENAME, Context.MODE_PRIVATE);
        return sp.getInt(key,value);
    }
}
